package com.business.common.utils;

import java.util.regex.Pattern;

/**
 * 字段数据格式校验工具类
 * @author wuguixin
 */
public class FormatValidUtil {
	
	//手机号码 正则
	private static final String p1 = "^[0][1-9]{2,3}-[0-9]{5,10}$";//固定电话格式: 验证带区号的,中间有"-" 
	private static final String p2 = "^[1-9]{1}[0-9]{5,8}$";//固定电话格式:验证没有区号的 
	private static final String p3 = "^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9]|17[0|6|7|8])\\d{8}$";//移动电话格式
	private static final String[] ppp = new String[]{p1,p2,p3};
	
	//邮箱 正则
	private static final String e1 = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";//有一个点的，如zhangshan@163.com
	private static final String e2 = "^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w{2,3}){1,3})$";//@符号前有点的，如zhangshna.Mr@163.com
	private static final String[] ee = new String[]{e1,e2};
	
	/**
	 * 验证手机号码
	 * @param phone
	 * @return
	 * @author wuguixin
	 */
	public static boolean matchPhone(String phone){
		for(String p:ppp){
			if (Pattern.matches(p, phone))return true;
		}
		return false;
	}
	
	
	
	/**
	 * 验证邮箱
	 * @param email
	 * @return
	 * @author wuguixin
	 */
	public static boolean matchEmail(String email){ 
		for(String e:ee){
			if (Pattern.matches(e, email))return true;
		}
		return false;
	}

	//测试
	public static void main(String[] args){
		System.out.println(FormatValidUtil.matchPhone("13714953422"));
	}



	
}
